package com.polaris.live.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.polaris.live.R
import com.polaris.live.databinding.WidgetUserRoundStateBinding
import com.polaris.live.im.sfs.bean.live.ext.UserBasicVo
import com.polaris.live.utils.state.UserStateUtils

/**
 * 用户圆形状态
 *
 * @author Created by 半仙 on 2024/6/27/027 20:28
 */
class UserRoundStateView(context: Context, attrs: AttributeSet?) : ConstraintLayout(context, attrs) {

    private val mBinding = WidgetUserRoundStateBinding.inflate(LayoutInflater.from(context), this)

    fun setState(userBasic: UserBasicVo) {
        mBinding.apply {
            when (val state = UserStateUtils.resolveUserState(userBasic)) {
                UserStateUtils.USER_STATE_ONLINE, UserStateUtils.USER_STATE_OFFLINE, UserStateUtils.USER_STATE_BUSY -> {
                    vState.visibility = View.VISIBLE
                    ivStateLive.visibility = View.GONE
                    when (state) {
                        UserStateUtils.USER_STATE_ONLINE -> {
                            vState.setBackgroundResource(R.drawable.ic_user_space)
                        }

                        UserStateUtils.USER_STATE_OFFLINE -> {
                            vState.setBackgroundResource(R.drawable.shape_session_state_offline)
                        }

                        UserStateUtils.USER_STATE_BUSY -> {
                            vState.setBackgroundResource(R.drawable.ic_user_space)
//                            vState.setBackgroundResource(R.drawable.shape_session_state_busy)
                        }

                        else -> {
                            vState.visibility = View.GONE
                            ivStateLive.visibility = View.GONE
                        }
                    }
                }

                UserStateUtils.USER_STATE_LIVE, UserStateUtils.USER_STATE_MATCH, UserStateUtils.USER_STATE_PARTY, UserStateUtils.USER_STATE_GAME -> {
                    vState.visibility = View.GONE
                    ivStateLive.visibility = View.VISIBLE
                    when (state) {
                        UserStateUtils.USER_STATE_LIVE -> {
                            vState.visibility = View.VISIBLE
                            ivStateLive.visibility = View.GONE
                            vState.setBackgroundResource(R.drawable.ic_user_space)
//                            ivStateLive.setImageResource(null)
                        }

                        UserStateUtils.USER_STATE_MATCH -> {
                            vState.visibility = View.VISIBLE
                            ivStateLive.visibility = View.GONE
                            vState.setBackgroundResource(R.drawable.ic_user_space)
//                            ivStateLive.setImageResource(R.drawable.icon_list_match)
                        }

                        UserStateUtils.USER_STATE_PARTY -> {
                            ivStateLive.setImageResource(R.drawable.icon_party)
                        }

                        UserStateUtils.USER_STATE_GAME -> {
                            ivStateLive.setImageResource(R.drawable.icon_list_gameing)
                        }

                        else -> {
                            vState.visibility = View.GONE
                            ivStateLive.visibility = View.GONE
                        }
                    }
                }

                else -> {
                    vState.visibility = View.GONE
                    ivStateLive.visibility = View.GONE
                }
            }
        }
    }
}